//
//  ByLoginVC.m
//  jinpuyiyuan_ios
//
//  Created by mc on 2017/12/4.
//  Copyright © 2017年 mc. All rights reserved.
//

#import "ByLoginVC.h"
// tabbar
#import "ByTabBarUser.h"
#import "ByTabBarDoctor.h"

// view
#import "ByViewLoginUserOperation.h"



@interface ByLoginVC ()
@property (nonatomic, strong) ByViewLoginUserOperation *userView;
@end

@implementation ByLoginVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"登录";
    [self createViews];
    [self addLeftBackBarButtonItem];
    self.view.backgroundColor = BY_TABLE_COLOR;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gettext:) name:@"registermodel" object:nil];
}
#pragma mark - 注册成功后返回
- (void)gettext:(NSNotification *)text {
    NSDictionary *dic = text.userInfo;
    UITextField *nameTf = [self.userView viewWithTag:10];
    UITextField *passTf = [self.userView viewWithTag:11];
    nameTf.text = dic[@"username"];
    passTf.text = dic[@"psw"];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"registermodel" object:nil];
}
#pragma mark - create views
- (void)createViews{
    UIView *logoHeaderView = [[UIView alloc] init];
    [self.view addSubview:logoHeaderView];
    [logoHeaderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(0));
        if (@available(iOS 11.0,*)) {
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
        }else{
            make.top.equalTo(self.view.mas_top);
        }
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT / 2 - 100));
    }];
    logoHeaderView.backgroundColor = BY_THEME_COLOR;
    
    self.userView = [[ByViewLoginUserOperation alloc] init];
    [self.view addSubview:self.userView];
    CGFloat margin = (SCREEN_HEIGHT / 2 - 100 - 30 * 2 - 15) / 2;
    [self.userView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(15));
        make.top.equalTo(@(margin));
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 30,SCREEN_HEIGHT / 2 - 100));
    }];
    self.userView.typeFrom = self.typeFrom;
    
    CGFloat width = [@"第三方登录" getSizeOfString:14].width + 20;
    UILabel *thirdLabel = [[UILabel alloc] init];
    [self.view addSubview:thirdLabel];
    [thirdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(width, 20));
        make.top.equalTo(self.userView.mas_bottom).offset(50);
        make.left.equalTo(@((SCREEN_WIDTH - width) / 2));
    }];
    thirdLabel.font = FONT(14);
    thirdLabel.textAlignment = NSTextAlignmentCenter;
    thirdLabel.textColor = [UIColor lightGrayColor];
    thirdLabel.text = @"第三方登录";
    
    UIView *line_left = [[UIView alloc] init];
    [self.view addSubview:line_left];
    [line_left mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(10));
        make.top.equalTo(thirdLabel.mas_top).offset(10);
        make.right.equalTo(thirdLabel.mas_left);
        make.height.equalTo(@(1));
    }];
    line_left.backgroundColor = [UIColor lightGrayColor];
    
    UIView *line_right = [[UIView alloc] init];
    [self.view addSubview:line_right];
    [line_right mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(thirdLabel.mas_right);
        make.right.equalTo(@(-10));
        make.top.equalTo(line_left);
        make.height.equalTo(@(1));
    }];
    line_right.backgroundColor = [UIColor lightGrayColor];
    
    UIImageView *wechatImg = [[UIImageView alloc] init];
    [self.view addSubview:wechatImg];
    [wechatImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@((SCREEN_WIDTH - 45) / 2));
        make.top.equalTo(thirdLabel.mas_bottom).offset(15);
        make.size.mas_equalTo(CGSizeMake(45, 45));
    }];
    wechatImg.backgroundColor = BY_THEME_COLOR;
}



@end
